﻿
Imports osi.root.connector
Imports osi.root.delegates
Imports osi.root.formation
Imports osi.root.procedure
Imports osi.root.utils
Imports osi.service.argument
Imports osi.service.selector

Partial Public Class device_constructor
    Private Shared Function resolve(Of T)(ByVal v As var,
                                          ByVal o As pointer(Of T),
                                          ByVal parameter_resolve As Func(Of pointer(Of T), event_comb),
                                          ByVal create_singleton_device_pool As  _
                                                    binder(Of _do_val_ref(Of T, 
                                                                             singleton_device_pool(Of T),
                                                                             Boolean), 
                                                              device_constructor(Of T))) As event_comb
        assert(Not parameter_resolve Is Nothing)
        Dim ec As event_comb = Nothing
        Return New event_comb(Function() As Boolean
                                  o.renew()
                                  ec = parameter_resolve(o)
                                  Return waitfor(ec) AndAlso
                                         goto_next()
                              End Function,
                              Function() As Boolean
                                  Return ec.end_result() AndAlso
                                         device_constructor(Of T).register_device(v,
                                                                                  +o,
                                                                                  create_singleton_device_pool) AndAlso
                                         goto_end()
                              End Function)
    End Function

    Public Shared Function resolve(Of T, PT) _
                                  (ByVal v As var,
                                   ByVal p As PT,
                                   ByVal o As pointer(Of T),
                                   Optional ByVal create_singleton_device_pool As  _
                                       binder(Of _do_val_ref(Of T, 
                                                                singleton_device_pool(Of T),
                                                                Boolean), 
                                                 device_constructor(Of T)) = Nothing) As event_comb
        Return resolve(v,
                       o,
                       Function(r) parameter_resolve(AddressOf resolve_only,
                                                     v,
                                                     p,
                                                     r),
                       create_singleton_device_pool)
    End Function

    Public Shared Function resolve(Of T, PT1, PT2) _
                                  (ByVal v As var,
                                   ByVal p As PT1,
                                   ByVal p2 As PT2,
                                   ByVal o As pointer(Of T),
                                   Optional ByVal create_singleton_device_pool As  _
                                       binder(Of _do_val_ref(Of T, 
                                                                singleton_device_pool(Of T),
                                                                Boolean), 
                                                 device_constructor(Of T)) = Nothing) As event_comb
        Return resolve(v,
                       o,
                       Function(r) parameter_resolve(AddressOf resolve_only,
                                                     v,
                                                     p,
                                                     p2,
                                                     r),
                       create_singleton_device_pool)
    End Function

    Public Shared Function resolve(Of T, PT1, PT2, PT3) _
                                  (ByVal v As var,
                                   ByVal p As PT1,
                                   ByVal p2 As PT2,
                                   ByVal p3 As PT3,
                                   ByVal o As pointer(Of T),
                                   Optional ByVal create_singleton_device_pool As  _
                                       binder(Of _do_val_ref(Of T, 
                                                                singleton_device_pool(Of T),
                                                                Boolean), 
                                                 device_constructor(Of T)) = Nothing) As event_comb
        Return resolve(v,
                       o,
                       Function(r) parameter_resolve(AddressOf resolve_only,
                                                     v,
                                                     p,
                                                     p2,
                                                     p3,
                                                     r),
                       create_singleton_device_pool)
    End Function

    Public Shared Function resolve(Of T, PT1, PT2, PT3, PT4) _
                                  (ByVal v As var,
                                   ByVal p As PT1,
                                   ByVal p2 As PT2,
                                   ByVal p3 As PT3,
                                   ByVal p4 As PT4,
                                   ByVal o As pointer(Of T),
                                   Optional ByVal create_singleton_device_pool As  _
                                       binder(Of _do_val_ref(Of T, 
                                                                singleton_device_pool(Of T),
                                                                Boolean), 
                                                 device_constructor(Of T)) = Nothing) As event_comb
        Return resolve(v,
                       o,
                       Function(r) parameter_resolve(AddressOf resolve_only,
                                                     v,
                                                     p,
                                                     p2,
                                                     p3,
                                                     p4,
                                                     r),
                       create_singleton_device_pool)
    End Function
End Class
